// pages/msg_procedure/msg_procedure.js
let app = getApp();
var my_pr = ''

Page({

    /**
     * 页面的初始数据
     */
    data: {
        loadModal: true,
        StatusBar: app.globalData.StatusBar,
        CustomBar: app.globalData.CustomBar,
        searchdata: [],
        goodsdata: [],
        xianshi: false
    },
    //输入框的确定搜索
    bindconfirm: function (e) {
        var that = this
        console.log('获取到的输入框中的id：', e.currentTarget.dataset.id)
        // 货品信息页面的搜索
        if (that.data.searchdata == '') {
            that.setData({
                searchdata: that.data.goodsdata
            })
        }
        if (e.detail.value == '') {
            that.setData({
                goodsdata: that.data.searchdata
            })
        } else {
            var data = that.data.goodsdata
            let s = e.detail.value

            function aa() {
                let _this = that
                let str = data
                console.log(s)
                let searchid = [];
                let sear = new RegExp(s);
                for (var j = 0; j < str.length; j++) {
                    if (sear.test(str[j].LITEMNAME)) {
                        searchid.push(str[j]);
                        console.log(searchid)
                    }
                }
                console.log(searchid)
                if (searchid != '') {
                    _this.setData({
                        goodsdata: searchid
                    })
                    wx.showToast({
                        title: '搜索成功',
                        icon: 'success',
                        duration: 1000
                    })
                } else {
                    wx.showToast({
                        title: '未搜索到相关信息',
                        icon: 'none',
                        duration: 2000,
                        mask: 'false'
                    })
                    _this.setData({
                        goodsdata: searchid
                    })
                }
            };
            aa();
        }
        console.log('搜索后赋值的列表：', that.data.goodsdata)

    },
    Jump(e) { // 跳转工序信息详情页面
        wx.navigateTo({
            url: '../msg_procedure_details/msg_procedure_details?lid=' + e.currentTarget.dataset.lid
        })
    },
    update() { // 添加工序信息
        wx.navigateTo({
            url: '../msg_procedure_add/msg_procedure_add'
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this
        app.globalData.number = 0
        console.log(app.globalData.user_phone)
        function pr() {
            wx.request({
                url: 'https://' + app.globalData.url + '/Process/findProcessByMobile',
                data: {
                    mobile: app.globalData.user_phone
                },
                method: 'GET',
                dataType: 'json',
                responseType: 'text',
                header: {
                    'content-type': 'application/json;charset=utf-8'
                },
                success: function (res) {
                    if (res.data.success == true) {
                        if (res.data.obj != '' && res.data.obj != null) {
                            that.setData({
                                goodsdata: res.data.obj,
                                loadModal: false,
                            })
                        } else {
                            that.setData({
                                loadModal: false,
                                xianshi: true
                            })
                            // wx.showModal({
                            //     title: '提示',
                            //     content: '当前数据为空',
                            //     showCancel: false,
                            //     confirmText: '确定',
                            //     success(res) {
                            //         if (res.confirm) {

                            //         }
                            //     }
                            // })
                        }
                    } else {
                        that.setData({
                            loadModal: false,
                            xianshi: true
                        })
                        wx.showModal({
                            title: '提示',
                            content: '当前用户' + app.globalData.lusername + res.data.msg,
                            showCancel: false,
                            confirmText: '确定',
                            success(res) {
                                if (res.confirm) {

                                }
                            }
                        })
                    }
                },
                fail: function (res) {
                    that.setData({
                        loadModal: false,
                        xianshi: true
                    })
                    wx.showModal({
                        title: '提示',
                        content: '访问服务器出错',
                        showCancel: false,
                        confirmText: '确定',
                        success(res) {
                            if (res.confirm) {

                            }
                        }
                    })
                },
            })
        }
        pr()
        my_pr = pr
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        if (app.globalData.number > 0) {
            my_pr()
        }
        app.globalData.number++
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})